package com.akk.module.yb.model;

import com.akk.PayConstants;
import com.akk.module.yb.utils.Digest;
import org.apache.commons.httpclient.methods.multipart.Part;
import org.apache.commons.httpclient.methods.multipart.StringPart;

import java.util.ArrayList;
import java.util.List;

/**
 * 信息修改请求
 */
public class EditMerchantRequest {
    private String mainCustomerNumber; // 代理商商户编号
    private String customerNumber; //商户编号
    private String modifyType; //修改类型
    private String whiteList; //白名单
    private String freezeDays; //冻结天数
    private String bankCardNumber; //银行卡号
    private String bankName; //开户行
    private String riskReserveDay; //结算周期
    private String manualSettle; //是否自助结算
    private String splitter; //分润方
    private String splitterProfitfee; //分润比率
    private String bindMobile; //手机号
    private String mailStr; //电子邮箱
    private String areaCode; //地区码
    private String hmac; //签名信息

    public String getMainCustomerNumber() {
        return mainCustomerNumber;
    }

    public void setMainCustomerNumber(String mainCustomerNumber) {
        this.mainCustomerNumber = mainCustomerNumber;
    }

    public String getCustomerNumber() {
        return customerNumber;
    }

    public void setCustomerNumber(String customerNumber) {
        this.customerNumber = customerNumber;
    }

    public String getModifyType() {
        return modifyType;
    }

    public void setModifyType(String modifyType) {
        this.modifyType = modifyType;
    }

    public String getWhiteList() {
        return whiteList;
    }

    public void setWhiteList(String whiteList) {
        this.whiteList = whiteList;
    }

    public String getFreezeDays() {
        return freezeDays;
    }

    public void setFreezeDays(String freezeDays) {
        this.freezeDays = freezeDays;
    }

    public String getBankCardNumber() {
        return bankCardNumber;
    }

    public void setBankCardNumber(String bankCardNumber) {
        this.bankCardNumber = bankCardNumber;
    }

    public String getBankName() {
        return bankName;
    }

    public void setBankName(String bankName) {
        this.bankName = bankName;
    }

    public String getRiskReserveDay() {
        return riskReserveDay;
    }

    public void setRiskReserveDay(String riskReserveDay) {
        this.riskReserveDay = riskReserveDay;
    }

    public String getManualSettle() {
        return manualSettle;
    }

    public void setManualSettle(String manualSettle) {
        this.manualSettle = manualSettle;
    }

    public String getSplitter() {
        return splitter;
    }

    public void setSplitter(String splitter) {
        this.splitter = splitter;
    }

    public String getSplitterProfitfee() {
        return splitterProfitfee;
    }

    public void setSplitterProfitfee(String splitterProfitfee) {
        this.splitterProfitfee = splitterProfitfee;
    }

    public String getBindMobile() {
        return bindMobile;
    }

    public void setBindMobile(String bindMobile) {
        this.bindMobile = bindMobile;
    }

    public String getMailStr() {
        return mailStr;
    }

    public void setMailStr(String mailStr) {
        this.mailStr = mailStr;
    }

    public String getAreaCode() {
        return areaCode;
    }

    public void setAreaCode(String areaCode) {
        this.areaCode = areaCode;
    }

    public String getHmac() {
        return hmac;
    }

    public void setHmac(String hmac) {
        this.hmac = hmac;
    }

    public static String signature(EditMerchantRequest request) {
        StringBuffer sb = new StringBuffer();
        sb.append(request.getMainCustomerNumber() == null ? "" : request.getMainCustomerNumber());
        sb.append(request.getCustomerNumber() == null ? "" : request.getCustomerNumber());
        switch (request.getModifyType()) {
            case "1":
                sb.append(request.getWhiteList() == null ? "" : request.getWhiteList());
                sb.append(request.getFreezeDays() == null ? "" : request.getFreezeDays());
            case "2":
                sb.append(request.getBankCardNumber() == null ? "" : request.getBankCardNumber());
                sb.append(request.getBankName() == null ? "" : request.getBankName());

            case "3":
                sb.append(request.getRiskReserveDay() == null ? "" : request.getRiskReserveDay());
                sb.append(request.getManualSettle() == null ? "" : request.getManualSettle());
            case "4":
                sb.append(request.getSplitter() == null ? "" : request.getSplitter());
                sb.append(request.getSplitterProfitfee() == null ? "" : request.getSplitterProfitfee());
            case "6":
                sb.append(request.getBindMobile() == null ? "" : request.getBindMobile());
                sb.append(request.getMailStr() == null ? "" : request.getMailStr());
                sb.append(request.getAreaCode() == null ? "" : request.getAreaCode());
        }

        System.out.println(sb.toString());
        System.out.println(Digest.hmacSign(sb.toString(), PayConstants.YB_PARAMS_HMAC_KEY));
        return Digest.hmacSign(sb.toString(), PayConstants.YB_PARAMS_HMAC_KEY);

    }

    public static Part[] builderPart(EditMerchantRequest request) {
        List<Part> parts = new ArrayList<Part>();
        parts.add(new StringPart("mainCustomerNumber", request.getMainCustomerNumber() == null ? "" : request.getMainCustomerNumber(), "UTF-8"));
        parts.add(new StringPart("customerNumber", request.getCustomerNumber() == null ? "" : request.getCustomerNumber(), "UTF-8"));
        parts.add(new StringPart("whiteList", request.getWhiteList() == null ? "" : request.getWhiteList(), "UTF-8"));
        parts.add(new StringPart("freezeDays", request.getFreezeDays() == null ? "" : request.getFreezeDays(), "UTF-8"));
        parts.add(new StringPart("modifyType", request.getModifyType() == null ? "" : request.getModifyType(), "UTF-8"));
        parts.add(new StringPart("bankCardNumber", request.getBankCardNumber() == null ? "" : request.getBankCardNumber(), "UTF-8"));
        parts.add(new StringPart("bankName", request.getBankName() == null ? "" : request.getBankName(), "UTF-8"));
        parts.add(new StringPart("riskReserveDay", request.getRiskReserveDay() == null ? "" : request.getRiskReserveDay(), "UTF-8"));
        parts.add(new StringPart("manualSettle", request.getManualSettle() == null ? "" : request.getManualSettle(), "UTF-8"));
        parts.add(new StringPart("splitter", request.getSplitter() == null ? "" : request.getSplitter(), "UTF-8"));
        parts.add(new StringPart("splitterProfitFee", request.getSplitterProfitfee() == null ? "" : request.getSplitterProfitfee(), "UTF-8"));
        parts.add(new StringPart("bindMobile", request.getBindMobile() == null ? "" : request.getBindMobile(), "UTF-8"));
        parts.add(new StringPart("mailStr", request.getMailStr() == null ? "" : request.getMailStr(), "UTF-8"));
        parts.add(new StringPart("areaCode", request.getAreaCode() == null ? "" : request.getAreaCode(), "UTF-8"));
        parts.add(new StringPart("hmac", request.getHmac() == null ? "" : request.getHmac(), "UTF-8"));

        return parts.toArray(new Part[parts.size()]);
    }
}
